(function(window) {
	var util=new Object();
	var _keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=";
	util.alert=function(txt,call){
		var options={};
		options.title="提示";
		options.call=call;
		return _alert(txt,options);
	};
	util.warning=function(txt,call){
		var options={};
		options.title="警告";
		options.icon=0;
		options.call=call;
		return _alert(txt,options);
	};
	util.error=function(txt,call){
		var options={};
		options.title="错误";
		options.icon=2;
		options.call=call;
		return _alert(txt,options);
	};
	util.confirm=function(txt,ok,cancel){
		layer.confirm(txt, {
    		title:"提示",
    		icon:3
    	}, function(i) {
    		layer.close(i);
    		var a="function"==typeof ok;
			if(a){ok()}
    	},function(i){
    		layer.close(i);
    		var a="function"==typeof cancel;
			if(a){cancel()}
    	});
	};
	util.promptText=function(txt,ok,value){
		var props={};
		props.title=txt;
		props.formType=0;
		if(value){
			props.value=value;
		}
		_prompt(props,ok);
	};
	util.promptTextarea=function(txt,ok,value){
		var props={};
		props.title=txt;
		props.formType=2;
		if(value){
			props.value=value;
		}
		_prompt(props,ok);
	};
	_prompt=function(props,ok){
		layer.prompt(props,
				function(text,i) {
					layer.close(i);
					var a="function"==typeof ok;
					if(a){ok(text)}
				});
	}
	function _alert(txt,options){
		var call=options.call;
		options._call=function(index){
			layer.close(index);
			var a="function"==typeof call;
			if(a){call()}
		};
		return layer.alert(txt,options,options._call);
	};
	util.load=function(){
		var params={};
		params.shade=[0.6,'#999'];
		return layer.load(3,params);
	};
	util.getParameter=function (name){
		url=window.location.search;
		var r = new RegExp("(\\?|#|&)" + name + "=([^&#]*)(&|#|$)"),
	    m = url.match(r);
		return (!m ? "" : m[2]);
	};
	util.checkInvalid=function(data){
		var _data={};
		for (var k in data) {
			var v=data[k];
			if(typeof v!='undefined'&&v.toString().length>0) {
				_data[k]=v;
			}
		};
		return _data;
	};
	util.checkEmail=function(b) {
	    var a = /^([a-zA-Z0-9-_]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
	    return a.test(b);
	};
	util.checkPhone=function(b) {
	    var a = /^1[34578]\d{9}$/;
	    return a.test(b);
	};
	util.reset=function(data){
		for(var k in data){
			data[k]="";
		}
	};
	util.confusion=function(){
		var prefix=new Date().getTime();
		var suffix=Math.random().toString(16).substr(2);
		return prefix+"-"+suffix;
	};
	util.base64Encode=function(input){
		return encode(input);
	};
	util.base64Decode=function(input){
		return decode(input);
	};
	util.startWith=function(s1,s2){
		if (s1 == null || s1 == "" || s1.length == 0) {
			return false;
		}
		if (s2 == null || s2 == "" || s2.length == 0) {
			return false;
		}
		if (s2.length > s1.length) {
			return false;
		}
		if (s1.substr(0, s2.length) == s2) {
			return true;
		} else {
			return false;
		}
		return false;
	};
	util.laydate=function(config){
		var _config={};
		_config.format="yyyy-MM-dd HH:mm:ss";
		_config.calendar=true;
		_config.theme="molv";
		_config.mark={
			'0-4-5': '清明',
			'0-7-1': '建党',
			'0-8-1': '建军'
		};
		$.extend(_config, config);
		laydate.render(_config);
	};
	util.laypage=function(config){
		var _config={};
		_config.groups=5;
		_config.first="首页";
		_config.last="尾页";
		_config.layout=['prev','page', 'next', 'skip','count'];
		$.extend(_config, config);
		laypage.render(_config);
	};
	util.get=function(params,callback){
		params.type="GET";
		request(params,callback);
	};
	util.exportFile=function(action,params,method){
		var $form=$("<form style='display:none'></form>");
		for ( var key in params) {
			var value=params[key];
			if(typeof value!='undefined'&&value.toString().length>0) {
				var  $input=$("<input type='hidden' name='"+key+"' value='"+value+"' />")
				$form.append($input);
			}
		}
		var _action=action;
		if(util.startWith(action,"/")){
			action=ctx+action;
		}
		var _method=method||"POST";
		$form.attr('action',_action);
        $form.attr('method',_method);
        $form.appendTo("body");
		$form.submit();
		$form.remove();
	};
	util.syncGet=function(params){
		params.async=false;
		params.type="GET";
		request(params);
	};
	util.post=function(params,callback){
		params.type="POST";
		request(params,callback);
	};
	util.syncPost=function(params){
		params.async=false;
		params.type="POST";
		request(params);
	};
	function request(params,callback){
		var _data=params.data;
		params.data=_data?util.checkInvalid(_data):_data;
		var dataType=params.dataType||"json";
		var contentType=params.contentType||"application/x-www-form-urlencoded;charset=UTF-8";
		var _success=params.success;
		var _error=params.error;
		var _url=params.url;
		if(util.startWith(_url,"/")){
			params.url=ctx+_url;
		}
		params.success=function(result){
			var status=result.status;
			var data=result.data;
			if(status=='success'){
				if($.isFunction(_success)){
					_success(data);
					callback&&callback();
				}
			}else{
				var code=result.errorCode;
				var errorMsg=result.errorMsg;
				if(code=='90000'){
					window.top.location.href="login";
					return ;
				};
				if($.isFunction(params.fail)){
					params.fail(code,errorMsg);
				}else{
					util.error(errorMsg);
				}
			}
		};
		params.error=function(e1,e2,e3){
			if($.isFunction(_error)){
				_error(e1,e2,e3);
			}else{
				util.error("系统错误，请稍后重试");
			}
		};
		params.dataType=dataType;
		params.contentType=contentType;
		$.ajax(params);
	};
	function encode(input) {
		var output = "";
		var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
		var i = 0;
		input = _utf8_encode(input);
		while (i < input.length) {
			chr1 = input.charCodeAt(i++);
			chr2 = input.charCodeAt(i++);
			chr3 = input.charCodeAt(i++);
			enc1 = chr1 >> 2;
			enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
			enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
			enc4 = chr3 & 63;
			if (isNaN(chr2)) {
				enc3 = enc4 = 64;
			} else if (isNaN(chr3)) {
				enc4 = 64;
			}
			output = output + _keyStr.charAt(enc1) + _keyStr.charAt(enc2)
				+ _keyStr.charAt(enc3) + _keyStr.charAt(enc4);
		}
		output = output.replace(/=/g, "");
		return output;
	};
	function decode(input) {
		var output = "";
		var chr1, chr2, chr3;
		var enc1, enc2, enc3, enc4;
		var i = 0;
		var length = input.length;
		switch (length % 4) {
			case 2: { input += "=="; break; }
			case 3: { input += "="; break; }
			default: break;
		}
		input = input.replace(/[^A-Za-z0-9\-\_\=]/g, "");
		while (i < length) {
			enc1 = _keyStr.indexOf(input.charAt(i++));
			enc2 = _keyStr.indexOf(input.charAt(i++));
			enc3 = _keyStr.indexOf(input.charAt(i++));
			enc4 = _keyStr.indexOf(input.charAt(i++));
			chr1 = (enc1 << 2) | (enc2 >> 4);
			chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
			chr3 = ((enc3 & 3) << 6) | enc4;
			output = output + String.fromCharCode(chr1);
			if (enc3 != 64) {
				output = output + String.fromCharCode(chr2);
			}
			if (enc4 != 64) {
				output = output + String.fromCharCode(chr3);
			}
		}
		output = _utf8_decode(output);
		return output;
	};
	function _utf8_encode(string) {
		string = String(string).replace(/\r\n/g, "\n");
		var utftext = "";
		for (var n = 0; n < string.length; n++) {
			var c = string.charCodeAt(n);
			if (c < 128) {
				utftext += String.fromCharCode(c);
			} else if ((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			} else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}

		}
		return utftext;
	};
	function _utf8_decode(utftext) {
		var string = "";
		var i = 0;
		var c = 0;
		var c1 = 0;
		var c2 = 0;
		while (i < utftext.length) {
			c = utftext.charCodeAt(i);
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			} else if ((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i + 1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			} else {
				c2 = utftext.charCodeAt(i + 1);
				c3 = utftext.charCodeAt(i + 2);
				string += String.fromCharCode(((c & 15) << 12)
					| ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
		}
		return string;
	};
	window.util=util;
})(window);
$(function(){
	lay_config={};
	lay_config.anim=0;
	lay_config.title="提示";
	lay_config.shade=[0.6,'#999'];
	lay_config.skin='layui-layer-molv';
	lay_config.closeBtn=0;
	layui.use('layer',function(){
		layer=layui.layer;
		layer.config(lay_config);
		_initialize();
	});
});
function _initialize(){
	if(typeof(initialize)!='undefined'){
		initialize();
	}else if(typeof(initVue)!='undefined'){
		initVue();
	}else if(typeof(vue)!='undefined'&&typeof(vue.initialize)!='undefined'){
		vue.initialize();
	};
};